﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IP.Core.IPData;
using IP.Core.IPUserService;
using BKIDS.CDBNames;
using IP.Core.IPCommon;
using BKIDS;
using BKIUS;

using System.Data;
public partial class DanhMuc_F200_Doi_tac : System.Web.UI.Page
{
    #region Members
    US_DM_DOI_TAC m_us_doi_tac = new US_DM_DOI_TAC();
    DS_DM_DOI_TAC m_ds_doi_tac = new DS_DM_DOI_TAC();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    // Load dữ liệu lên lưới.
    private void load_data_2_grid()
    {
        m_lbl_nhan_doi_tac.Text = "Kết quả lọc dữ liệu";
        m_us_doi_tac.FillDataset(m_ds_doi_tac);
        m_grv_dm_doi_tac.DataSource = m_ds_doi_tac.DM_DOI_TAC;
        m_grv_dm_doi_tac.DataBind();
    }

    // Load dữ liệu từ form vào 1 object
    private void form_2_us_object(US_DM_DOI_TAC ip_us_dm_doi_tac)
    {
        //ip_us_dm_doi_tac.strHO_TEN = m_txt_ho_ten.Text;
        //ip_us_dm_doi_tac.strEMAIL = m_txt_email.Text;
        //ip_us_dm_doi_tac.strSO_DIEN_THOAI = m_txt_so_dien_thoai.Text;
        //ip_us_dm_doi_tac.strDIA_CHI = m_txt_dia_chi.Text;
        //ip_us_dm_doi_tac.strNOI_CONG_TAC = m_txt_noi_cong_tac.Text;
        //ip_us_dm_doi_tac.strVI_TRI_CONG_TAC = m_txt_vi_tri_cong_tac.Text;
    }
    //

    protected void m_cmd_tao_moi_Click(object sender, EventArgs e)
    {
        try
        {
            // giờ viết lệnh thực thi choswjk kiện insert
            // B1: Thu thập dữ liệu vào us
            form_2_us_object(m_us_doi_tac);

            // Bước 2 : gen procedure, dùng tool
            // B3: insert vào CSDL
            m_us_doi_tac.Insert();
            // b4: Load lại lứoi
            load_data_2_grid();
            // Reset control

        }
        catch (Exception v_e)
        {
            Response.Write(v_e.Message); // có lỗi nó sẽ báo ra màn hình
        }
    }

    protected void m_btn_xem_toan_bo_Click(object sender, EventArgs e)
    {
        load_data_2_grid();
        m_grv_dm_doi_tac.Visible = true;
        An_thi_form_Cap_nhat_doi_tac();
        m_btn_them_doi_tac.Visible = false;
        m_btn_xoa_trang.Visible = false;
        m_btn_them_moi_s.Visible = true;
        
    }
    protected void btn_them_moi_Click(object sender, EventArgs e)
    {
        m_lbl_nhan_doi_tac.Text = "Thêm mới đối tác";
        Hien_thi_form_Cap_nhat_doi_tac();
        m_grv_dm_doi_tac.Visible = false;
        m_btn_them_moi_s.Visible = false;
        m_btn_them_doi_tac.Visible = true;
        m_btn_xoa_trang.Visible = true;
    }
    protected void m_btn_xoa_trang_Click(object sender, EventArgs e)
    {
        Clear_textbox_form_doi_tac();
    }

    #region Hiển thị, ẩn form 
    public void Hien_thi_form_Cap_nhat_doi_tac()
    {
        m_lbl_ho_ten.Visible = true;
        m_txt_ho_ten.Visible = true;
        m_lbl_ngay_sinh.Visible = true;
        m_txt_ngay_sinh.Visible = true;
        m_lbl_gioi_tinh.Visible = true;
        m_rdl_gender.Visible = true;
        m_lbl_so_dt.Visible = true;
        m_txt_so_dien_thoai.Visible = true;
        m_lbl_email.Visible = true;
        m_txt_email.Visible = true;
        m_lbl_dia_chi.Visible = true;
        m_txt_dia_chi.Visible = true;
        lbl_noi_cong_Tac.Visible = true;
        m_txt_noi_cong_tac.Visible = true;
        lbl_vi_tri_cong_tac.Visible = true;
        m_txt_vi_tri_cong_tac.Visible = true;
    }
    public void An_thi_form_Cap_nhat_doi_tac()
    {
        m_lbl_ho_ten.Visible = false;
        m_txt_ho_ten.Visible = false;
        m_lbl_ngay_sinh.Visible = false;
        m_txt_ngay_sinh.Visible = false;
        m_lbl_gioi_tinh.Visible = false;
        m_rdl_gender.Visible = false;
        m_lbl_so_dt.Visible = false;
        m_txt_so_dien_thoai.Visible = false;
        m_lbl_email.Visible = false;
        m_txt_email.Visible = false;
        m_lbl_dia_chi.Visible = false;
        m_txt_dia_chi.Visible = false;
        lbl_noi_cong_Tac.Visible = false;
        m_txt_noi_cong_tac.Visible = false;
        lbl_vi_tri_cong_tac.Visible = false;
        m_txt_vi_tri_cong_tac.Visible = false;
    }
    #endregion

    public void Clear_textbox_form_doi_tac()
    {
        m_txt_ho_ten.Text = "";
        m_txt_dia_chi.Text = "";
        m_txt_email.Text = "";
        m_txt_ngay_sinh.Text = "";
        m_txt_noi_cong_tac.Text = "";
        m_txt_vi_tri_cong_tac.Text = "";
        m_txt_so_dien_thoai.Text = "";
    }

    
}